package net.huashitong.synthetical.AddressBook.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.synthetical.AddressBook.entity.AddressBookUser;
import net.huashitong.synthetical.AddressBook.filter.BookFilter;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class AddressBookUserDao extends StringDao<AddressBookUser> {


    public List<AddressBookUser> queryByFilter(BookFilter filter){
        GenericQuery query  = createQuery("obj");
        if(StringUtils.isNotBlank(filter.getDepartCode()))
            query.append(" and obj.departCode =:departCode ").setParam("departCode",filter.getDepartCode());
        if(StringUtils.isNotBlank(filter.getDepartUser()))
            query.append(" and obj.departCode like:departUser ").setParam("departUser",
                    StringUtils.getLikewords(filter.getDepartUser()));
        if(StringUtils.isNotBlank(filter.getUserIPhone()))
            query.append(" and obj.userIPhone =:userIPhone").setParam("userIPhone",filter.getUserIPhone());
        if(StringUtils.isNotBlank(filter.getEmailaddre()))
            query.append(" and obj.emailaddre like:emailaddre").setParam("emailaddre",
                    StringUtils.getLikewords(filter.getEmailaddre()));


        return  query.listResult(filter);
    }

}
